﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace MethodWorx.Core.Extensions
{
    public static class DateTimeExtensions
    {
        public static int CalculateAge(this DateTime src, DateTime now)
        {
            // get the difference in years
            int years = now.Year - src.Year;
            // subtract another year if we're before the
            // birth day in the current year
            if (now.Month < src.Month || (now.Month == src.Month && now.Day < src.Day))
                --years;

            return years;

            throw new NotImplementedException();
        }

        public static bool IsToday(this DateTime src)
        {
            DateTime now = DateTime.Now;
            return IsSameDay(src, now);
        }


        public static bool IsSameDay(this DateTime src, DateTime check)
        {
            return (src.Year == check.Year && src.Month == check.Month && src.Day == check.Day);
        }

        public static bool IsThisWeek(this DateTime src)
        {
            DateTime now = DateTime.Now;
            bool isLastWeek = false;

            //  go back to sunday
            DateTime sunday = now.AddDays(-(int)now.DayOfWeek);

            for (int i = 0; i < 7; i++)
            {
                //  add the day on
                DateTime day = sunday.AddDays(i);
                isLastWeek = IsSameDay(src, day);
                if (isLastWeek)
                    break;
            }

            return isLastWeek;
        }
    }
}
